home *** CD-ROM | disk | FTP | other *** search
- /* gcvt.c, from pp.176-177 of Turbo C Bible */
- /* Converts a double-precision floating-point value into a string
- using a specified number of significant digits
- and having an embedded decimal point. */
- #include <stdio.h>
- #include <math.h>
- #include <stdlib.h>
- main(int argc, char **argv)
- {
- int significant_digits = 6;
- double value;
- char buffer[80]; /* Buffer for gcvt */
- if(argc < 2)
- {
- printf("Usage: %s <value>\n", argv[0]);
- }
- else
- { /* Convert the number to internal */
- value = atof(argv[1]); /* form. Then call gcvt. */
- gcvt(value, significant_digits, buffer);
- printf("Buffer from gcvt contains: %s\n", buffer);
- }
- }